package sql_film;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.db.DBConfiguration;
import org.apache.hadoop.mapreduce.lib.db.DBInputFormat;
import org.apache.hadoop.mapreduce.lib.db.DBOutputFormat;
import org.apache.log4j.BasicConfigurator;

public class Driver {
    public static void main(String[] args) throws Exception {
        BasicConfigurator.configure();
        Configuration conf = new Configuration();

        DBConfiguration.configureDB(conf,"com.mysql.jdbc.Driver","jdbc:mysql://localhost:3306/data?useUnicode=true&characterEncoding=UTF-8","root","200028");
        Job job = Job.getInstance(conf);
        job.setJarByClass(Driver.class);

        job.setMapperClass(MapTest.class);
        job.setMapOutputKeyClass(NullWritable.class);
        job.setMapOutputValueClass(Movie_result.class);

        job.setReducerClass(RedTest.class);
        job.setOutputKeyClass(Movie_result.class);
        job.setOutputValueClass(NullWritable.class);

        String [] f1 ={"rank","name","actor","grade","num","common"};
        String [] f2 ={"name","actor","grade","num","common"};
        DBInputFormat.setInput(job,Movie.class,"douban",null,null,f1);
        DBOutputFormat.setOutput(job,"film_result",f2);
        System.exit(job.waitForCompletion(true)?0:1);

    }
}
